<?php
namespace Admin\Controller;
use Think\Controller;
class ResController extends Controller {
    public function index(){
 		$ReslModel=M('Res');
        $res= $ReslModel->where('status=1')->order('posttime desc')->select(); 
        $this->assign('data',$res);
        $this->display();
    }
    
    public function add(){


        if (IS_POST) {
             print_r($_POST);
            exit;
            $data=array(
                    'title'=>addslashes(I("post.title")),
                    'link'=>I('post.link'),
                    'category'=>I('post.category'),
                    'level'=>I('post.level'),
                    'yuanjia'=>trim(I('post.yuanjia')),
                    'current'=>trim(I('post.current')),
                    'content'=>addslashes(I('post.content')),
                    'from'=>addslashes(I('post.from')),
                );

/******************************************************************************/

   
        }else{
            $starttime=toDate(time());
            $this->assign('starttime',$starttime);
            $this->display();
        }
    }    



    public function checkform(){

        $yuanjia=trim(I('yuanjia'));
        $current=trim(I('current'));
        $starttime=I('starttime');
        $endtime=I('endtime');
        $starttime_int=toTime($starttime);
        $endtime_int=toTime($endtime);
        $nowTime=time();
        $res=array();

        // 判断价格数字化
    	if ((!empty($yuanjia))&&(!is_numeric($yuanjia))) {
            $res=array('msg'=>'价格必须位数字','code'=>1);
    	}

    	if ((!empty($current))&&(!is_numeric($current))) {
            $res=array('msg'=>'价格必须位数字','code'=>1);
     	}

        // 判断时间的对比
        if ( $nowTime> $starttime_int) {
            $res=array('msg'=>'开始时间不得晚于当前时间','code'=>1);
         }


        if ((!empty($endtime_int))&&($endtime_int<$starttime_int)) {
            $res=array('msg'=>'线报时间不得小于开始时间','code'=>1);
         }

         $res=array('msg'=>'提交成功','code'=>0);

        return json_encode($res);


/*
        $myflie=$_FILES['file']; 
    

        if ($myflie['name']==''||empty($myflie['name'])||!isset($myflie['name'])) {
            $LevelModel=M('Res');
            $res=$User->add($data);
            if ($res) {
                 $this->success('发布成功','index/index',1);
            }else{
                $this->error('发布失败',1);
            }

        }else{
             $upload = new \Think\Upload();
             $upload->maxSize   =     3145728 ;
             $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');
             $upload->savePath  =      './Public/Uploads/';
             $info   =   $upload->uploadOne($myflie); 
             if(!$info) { 
                $this->error($upload->getError(),1);   

             }else{ 
                $data['path']= $info['savepath'].$info['savename'];    //图片保存的路径+图片名称  保存到数据库即可
                $LevelModel=M('Res');
                $res=$User->add($data);
                if ($res) {
                     $this->success('发布成功','index/index',1);
                }else{
                    $this->error('发布失败',1);
                }
             }
        }
*/


        
    }
}
